package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.question.DeleteQuestionBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.team.db.dao.ext.QuestionDao;
import com.zhuss.team.db.entity.Question;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/26 13:25
 */
@Component("questionDelete")
public class QuestionDelete extends AbstractProcessor<Object, DeleteQuestionBo> implements Processor<Object, DeleteQuestionBo> {

    @Autowired
    private QuestionDao questionDao;

    @Override
    public Object process(DeleteQuestionBo bo) throws WpsException {
        Question q = new Question();
        q.setQuestionId(bo.getQuestionId());
        q.setDeleted(bo.getDeleted());

        q.setModifier(bo.getConcurrentUserName());
        q.setModifierId(bo.getConcurrentUserId());
        q.setModifyTime(new Date());
        questionDao.delete(q);
        return null;
    }

    @Override
    public Object log(DeleteQuestionBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.协同发布.key());
        record.setAction(LogActionEnum.问题删除.key());
        record.setTargetId(param.getQuestionId());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(DeleteQuestionBo deleteQuestionBo) throws WpsException {

    }
}
